home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 003 / db3tech.arc / WORDWRAP.TXT < prev   
Encoding:
Text File  |  1980-01-01  |  2.5 KB  |  94 lines

  1. * Program..: Wordwrap.PRC
  2. * Author...: Tom Rettig
  3. * Date.....: January 3, 1985
  4. * Notes....: Two procedures for output of long character fields 
  5. *            with word wrapping at a specified column.
  6. *            Note the use of .PRC for the extension of a
  7. *            procedure file.
  8. * Input 'line' can be up to 254 chars.
  9. * 'max' is an integer for the maximum output string length.
  10. *
  11. PROCEDURE Wordwrap
  12. PARAMETERS line, max
  13. string = TRIM( line )
  14. ith = 1
  15. IF [] < string
  16.    DO WHILE LEN(string) > max .AND. AT(" ",SUBSTR(string,ith)) > 0
  17.       * Point to first space before column max...
  18.       DO WHILE .T.
  19.          * This construct was used because versions 1.0 and 1.1
  20.      * do not support DO WHILE <condition> with a semicolon.  
  21.          * (See page D3-32 in the dBASE III Anomalies Section 
  22.          * in this issue of TechNotes.)
  23.          IF ith-1 <= max .AND.;
  24.         AT(" ",SUBSTR(string,ith)) > 0 .AND.;
  25.             ith-1 + AT(" ",SUBSTR(string,ith)) <= max
  26.         *
  27.             ith = ith + AT(" ",SUBSTR(string,ith))
  28.          ELSE
  29.             EXIT
  30.          ENDIF
  31.       ENDDO
  32.       * Output first part of string.
  33.       DO Output WITH SUBSTR( string,1,ith-1 )
  34.       * Truncate first part of string from string.
  35.       IF ith < LEN( string )
  36.          string = SUBSTR( string,ith )
  37.          ith = 1
  38.       ENDIF
  39.    ENDDO
  40. ENDIF
  41. * Output last part of string.
  42. DO Output WITH string
  43. RETURN
  44. * EOP: Wordwrap
  45.  
  46. PROCEDURE Output
  47. PARAMETERS string
  48.    * A separate procedure is used for the output because
  49.    * output occurs at two locations in the Wordwrap procedure.
  50.    ? [   ] + string
  51. RETURN
  52. * EOP: Output
  53. * EOF: Wordwrap.PRC
  54.  
  55.  
  56. * Program..: Getty.PRG
  57. * Author...: Ray Love
  58. * Date.....: January 3, 1985
  59. * Notes....: Demonstrates Wordwrap.PRC by passing it the
  60. *            Gettysburg address with a length parameter
  61. *            determined by the user.
  62. SET TALK OFF
  63. SET PROCEDURE TO Wordwrap.PRC
  64. *
  65. * Initialize variables.
  66. getty = "Four score and seven years ago our fathers brought " +;
  67.         "forth, upon this continent, a new nation, conceived " +;
  68.         "in liberty, and dedicated to the proposition that " +;
  69.         "all men are created equal."
  70. wrap = 0
  71. CLEAR
  72. * Get right margin of output.
  73. @ 1,1 SAY "Enter line length (15 - 65) ";
  74.       GET wrap PICTURE "99" RANGE 15,65
  75. READ
  76. * Display right margin.
  77. @ 2,1 SAY SPACE( wrap ) + "*"
  78. * Call procedure and pass parameters.
  79. DO Wordwrap WITH getty, wrap
  80. CLOSE PROCEDURE
  81. SET TALK ON
  82. RETURN
  83. * EOF: Getty.PRG
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.